import { Component, OnInit, Injector, ViewChild, Output, EventEmitter, Input, ElementRef } from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import { Table } from 'primeng/table';
import { Paginator } from 'primeng/primeng';
import { StockZT_BaseInfoServiceProxy } from '@shared/service-proxies/stock-service-proxies'; 
import { CodeItemServiceProxy } from '@shared/service-proxies/stock-service-proxies';
// import { ToolingZT_BaseInfoServiceProxy } from '@shared/service-proxies/tooling-service-proxies';
import { CodeItemsTreeComponent } from '@app/shared/common/codeitemtree/codeitems-tree.component';
import { ToolingBaseFieldComponent } from './tooling-basefield.component';
@Component({
    templateUrl: './tooling-base-info.component.html',
    animations: [appModuleAnimation()],
    selector: 'tooling-base-info'
})
export class ToolingBaseInfoComponent extends AppComponentBase implements OnInit {
    @ViewChild('dataTable') dataTable: Table;
    @ViewChild('paginator') paginator: Paginator;
    @ViewChild('ouStockBase') ouStockBase: ToolingBaseFieldComponent;
    @Output() modalSelect = new EventEmitter<any>();
    @ViewChild('ouCodeItemsTree') ouCodeItemsTree: CodeItemsTreeComponent;
    @ViewChild('btnleft') btnleft: ElementRef;
    @ViewChild('btndiv') btndiv: ElementRef;
    @ViewChild('treediv') treediv: ElementRef;

    _edit = '1';
    _tree = '1';
    showContent: Boolean = true;
    showContent1: Boolean = false;
    @Input() set edit(val) {
        if (val) {
            this._edit = val;
        }
    }
    @Input() set showtree(val) {
        if (val) {
            this._tree = val;
        }
    }
    anyncing = false;
    filterText = '';

    constructor(
        injector: Injector,
        private _baseInfoServiceProxy: StockZT_BaseInfoServiceProxy,
        private _codeItemServiceProxy: CodeItemServiceProxy
    ) {
        super(injector);
    }

    ngOnInit() {}

    ouallSelected(event: any): void {
        this.ouStockBase.codeItemId = event.Id;
        this.ouStockBase.codeName = event.displayName;
        console.log(event.Id)
        console.log(this.ouStockBase)
        this.ouStockBase.getBaseField();
        this._codeItemServiceProxy.getToolingCodeItemFatherTree(event.Id).subscribe(result => {
            this.ouStockBase.filterText = result.items[0].code;
            this.ouStockBase.getBaseField();
        });
    }

    dataLoad(event?: number) {
        console.log(this.btndiv);
        if (this.ouCodeItemsTree) {
            console.log(this.btnleft.nativeElement);

            this.btnleft.nativeElement.setAttribute(
                'style',
                'max-width:15px;padding:0.65rem 0.4rem;background-color: white;margin-top:' + (event / 2 - 30) + 'px;'
            );
            this.ouCodeItemsTree.resetTreeHeight(event);
        }
    }
    ouSelected(event: any) {}

    rowselected(event) {
        this.modalSelect.emit(event);
    }
    showHide() {
        // this.showContent1=this.showContent1?false:true;
        // this.showContent=this.showContent?false:true;
        if (this._tree == '0') {
            this._tree = '1';
        } else if (this._tree == '1') {
            this._tree = '0';
        }
    }
}
